package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.small.util.ResponseResultDTO;
import com.stylefeng.guns.modular.system.dto.ConsumerOrderDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.ConsumerOrder;
import com.stylefeng.guns.modular.system.service.IConsumerOrderService;

/**
 * 订单表控制器
 *
 * @author fengshuonan
 * @Date 2019-09-09 22:00:37
 */
@Controller
@RequestMapping("/consumerOrder")
public class ConsumerOrderController extends BaseController {

    private String PREFIX = "/system/consumerOrder/";

    @Autowired
    private IConsumerOrderService consumerOrderService;

    /**
     * 跳转到订单表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "consumerOrder.html";
    }

    /**
     * 跳转到添加订单表
     */
    @RequestMapping("/consumerOrder_add")
    public String consumerOrderAdd() {
        return PREFIX + "consumerOrder_add.html";
    }

    /**
     * 跳转到修改订单表
     */
    @RequestMapping("/consumerOrder_update/{consumerOrderId}")
    public String consumerOrderUpdate(@PathVariable Integer consumerOrderId, Model model) {
        ConsumerOrder consumerOrder = consumerOrderService.selectById(consumerOrderId);
        model.addAttribute("item",consumerOrder);
        LogObjectHolder.me().set(consumerOrder);
        return PREFIX + "consumerOrder_edit.html";
    }

    /**
     * 获取订单表列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return consumerOrderService.selectList(null);
    }

    /**
     * 新增订单表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ConsumerOrder consumerOrder) {
        consumerOrderService.insert(consumerOrder);
        return SUCCESS_TIP;
    }

    /**
     * 删除订单表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer consumerOrderId) {
        consumerOrderService.deleteById(consumerOrderId);
        return SUCCESS_TIP;
    }

    /**
     * 修改订单表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ConsumerOrder consumerOrder) {
        consumerOrderService.updateById(consumerOrder);
        return SUCCESS_TIP;
    }

    /**
     * @api {get} /detail/{consumerOrderId}  订单表详情
     * @apiName  ConsumerOrderDetail
     * @apiGroup ConsumerOrder
     *
     * @apiParam {Number} consumerOrderId  订单id.
     *
     *  @apiSuccess {Object} ConsumerOrder  返回订单对象.
     *
     * @apiSuccessExample {json} Success-Response:
     *      HTTP/1.1 200 OK
     *    {
     * 		"message":"操作成功",
     * 	    "code":"200"
     *    }
     */
    @RequestMapping(value = "/detail/{consumerOrderId}")
    @ResponseBody
    public Object detail(@PathVariable("consumerOrderId") Integer consumerOrderId) {
        return consumerOrderService.selectById(consumerOrderId);
    }

    /**
     * @api {POST} /consumerOrder/searchOrder  用户或者技师查询订单
     * @apiName  searchOrder
     * @apiGroup ConsumerOrder
     *
     * @apiParam {Number} consumerId   消费者id.
     * @apiParam {Number} artificerId  技师id.
     * @apiParam {Number} status       订单状态.
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     * 	"data": [
     *                {
     * 			"address": "四川省-成都市-武侯区-红牌楼丽都世家B区",
     * 			"artificerId": 2,
     * 			"consumerId": 2,
     * 			"createTime": "2019-09-18 18:30:25",
     * 			"houseNumber": "908",
     * 			"id": 2,
     * 			"name": "刘先生",
     * 			"phone": "15982211111",
     * 			"remark": "速度，有点等会儿去吃饭",
     * 			"reserveType": 2,
     * 			"status": 1,
     * 			"subscribeMoney": 298.0,
     * 			"subscribeTime": "2019-09-18 18:30:41"
     *        }
     * 	],
     * 	"msg": "SUCCESS",
     * 	"status": "0000",
     * 	"userType": ""
     * }
     */
    @RequestMapping(value = "/searchOrder")
    @ResponseBody
    public ResponseResultDTO searchOrder(ConsumerOrderDTO param) {
        return consumerOrderService.searchOrder(param);
    }
}
